//资产管理
import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'manAssetManagePlanInfoM',
  state: {},
  effects: {
    //查询债券信息维护的表格
    *getDataList({ payload, callback }, { call, put }) {
      const res = yield call(api.manAssetManagePlanInfo.assetManagePlanInfo, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        callback();
        message.error(res ? res.msg || '查询列表失败!' : '查询列表失败!');
      }
    },

    //资产委外根据证券代码进行回填数据
    *assetManagePlanInfoDetail({ payload, callback }, { call, put }) {
      const res = yield call(api.manAssetManagePlanInfo.assetManagePlanInfoDetail, payload);
      if (res && res.code == 0) {
        callback(res.data.dataSource);
      } else {
        message.error(res.msg);
      }
    },

    //新增/编辑 资产委外数据
    *assetManagePlanInfoAdd({ payload, callback }, { call, put }) {
      const res = yield call(api.manAssetManagePlanInfo.assetManagePlanInfoAdd, payload);
      if (res && res.code == 0) {
        callback(true);
        message.success('操作成功！');
      } else {
        message.error(res.msg);
      }
    },

    //资产委外批量确认
    *assetManagePlanInfoConfirm({ payload, callback }, { call, put }) {
      const res = yield call(api.manAssetManagePlanInfo.assetManagePlanInfoConfirm, payload);
      if (res && res.code == 0) {
        callback(true);
      } else {
        message.error(res?.msg || '批量确认失败');
      }
    },

    //资产委外转非标
    *assetManagePlanInfoTranslate({ payload, callback }, { call, put }) {
      const res = yield call(api.manAssetManagePlanInfo.assetManagePlanInfoTranslate, payload);
      if (res && res.code == 0) {
        callback(true);
      } else {
        message.error(res.msg);
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
